define(['ash', 'game/constants/WorldCreatorConstants', 'game/constants/PlayerActionConstants', 'game/constants/UpgradeConstants', 'game/vos/ItemVO'], 
function (Ash, WorldCreatorConstants, PlayerActionConstants, UpgradeConstants, ItemVO) {

    var ItemConstants = {
        
        PLAYER_DEFAULT_STORAGE: 10,
        
        itemTypes: {
            // Equippable / slots:
            light: "Light",
            weapon: "Weapon",
            clothing_over: "Armor",
            clothing_upper: "Shirt",
            clothing_lower: "Legs",
            clothing_hands: "Hands",
            clothing_head: "Head",
            shoes: "Shoes",
            bag: "Bag",
            follower: "Follower",
            // Special effects / one-use:
            ingredient: "Ingredient",
            exploration: "Exploration",
            uniqueEquipment: "UniqueEquipment",
            // Just inventory - no effects:
            artefact: "Artefact",
            note: "Note",
        },
        
        itemBonusTypes: {
            light: "light",
            fight_att: "fight attack",
            fight_def: "fight defence",
            movement: "movement",
            bag: "bag",
            res_cold: "warmth",
            res_radiation: "radiation protection",
            res_poison: "poison protection",
            res_sunlight: "sunblindness protection",
        },
        
        itemDefinitions: {
            light: [
                new ItemVO("light1", "Lantern", "Light", {"light": 25}, true, true, false, "img/items/light-lantern.png",
                    "有微弱光线，可以维持在黑暗的地下走廊中的基本生存。", 1, 2),
                new ItemVO("light2", "Electric light", "Light", {"light": 75}, true, true, false, "img/items/light-electric.png",
                    "真正的旅行者所使用的高级灯。", 5, -1),
                new ItemVO("light3", "Ghost light", "Light", {"light": 125}, true, false, false, "img/items/light-ghost.png",
                    "据说幽灵灯可以让你看清更远的黑暗之地。", 15, 9),
            ],
            weapon: [
                new ItemVO("weapon1", "Shiv", "Weapon", {"fight attack": 2}, true, true, false, "img/items/weapon-shiv.png",
                    "简易尖锐的刺戳工具。", 1, 2),
                new ItemVO("weapon2", "Spear", "Weapon", {"fight attack": 5}, true, true, false, "img/items/weapon-shiv.png",
                    "老式但可靠的武器。", 5, 2),
                new ItemVO("weapon3", "Crossbow", "Weapon", {"fight attack": 11}, true, true, false, "img/items/weapon-shiv.png",
                    "一种致命的远程武器，由水平肢和安装在其上的弹射装置以及弹丸构成。", 8, 7),
                new ItemVO("weapon4", "Pistol", "Weapon", {"fight attack": 24}, true, true, false, "img/items/weapon-bomb.png",
                    "一支粗糙的单发手枪，就像是手持的微型加农炮。", 11, 7),
                new ItemVO("weapon5", "Revolver", "Weapon", {"fight attack": 52}, true, true, false, "img/items/weapon-bomb.png",
                    "一种更先进的手枪，允许在重装之前多次射击。", 14, 7),
                new ItemVO("weapon6", "Custom SMG", "Weapon", {"fight attack": 116}, true, true, false, "img/items/weapon-bomb.png",
                    "它可能是由废金属制成的，但它仍然是一种危险的武器。", 17, -1),
                new ItemVO("weapon7", "Improvised bazooka", "Weapon", {"fight attack": 225}, true, true, false, "img/items/weapon-bomb.png",
                    "强力但很重。管道结构、回收来的武器部件还有简易的弹药，看起来都有些不可靠。", 19, -1),
            ],
            clothing_over: [
                new ItemVO("clothing_over_1", "Warm Coat", "Armor", {"fight defence": 1, warmth: 20}, true, true, false, "img/items/clothing-2.png",
                    "抵抗寒冷的衣服", 1, 5),
                new ItemVO("clothing_over_2", "Biker jacket", "Armor", {"fight defence": 6, warmth: 10, "radiation protection": 3, "poison protection": 3}, true, false, false, "img/items/clothing-2.png",
                    "它不能让一个人无敌，但会给别人一种很强的错觉。", 7, 6),
                new ItemVO("clothing_over_3", "Scrap metal armor", "Armor", {"fight defence": 18, warmth: 0, "radiation protection": 5, "poison protection": 5}, true, true, false, "img/items/clothing-2.png",
                    "为了保护人所设计出的护甲。", 1, 7),
                new ItemVO("clothing_over_4", "Kevlar vest", "Armor", {"fight defence": 40, warmth: 0, "radiation protection": 0, "poison protection": 5}, true, true, false, "img/items/clothing-2.png",
                    "很重，但绝对值得。", 1, 7),
                new ItemVO("clothing_over_5", "Riot police vest", "Armor", {"fight defence": 100, warmth: 10, "radiation protection": 0, "poison protection": 10}, true, false, false, "img/items/clothing-3.png",
                    "在原来防护服的基础上进一步增加了适应环境的能力。", 17, 6),
                new ItemVO("clothing_over_6", "Exoskeleton", "Armor", {"fight defence": 290, warmth: 10, "radiation protection": 30, "poison protection": 20}, true, true, false, "img/items/clothing-3.png",
                    "在原来防护服的基础上进一步增加了适应环境的能力。", 18, -1),
            ],
            clothing_upper: [
                new ItemVO("clothing_upper_1", "Tattered shirt", "Shirt", {warmth: 1}, true, false, false, "img/items/clothing-rags.png",
                    "几乎没有什么布料在上面了，但现在不得不穿它。", 1, 2),
                new ItemVO("clothing_upper_2", "Factory uniform shirt", "Shirt", {"fight defence": 1, warmth: 3}, true, false, false, "img/items/clothing-2.png",
                    "在黑暗的通道和废弃的工厂中有种奇妙的舒适感。", 5, 4),
                new ItemVO("clothing_upper_3", "Guard shirt", "Shirt", {"fight defence": 2, warmth: 3}, true, true, false, "img/items/clothing-2.png",
                    "看起来很正式，但没有很好的保护能力。", 12, 4),
                new ItemVO("clothing_upper_4", "Protective shirt", "Shirt", {"fight defence": 10, warmth: 10, "radiation protection": 5, "poison protection": 5}, true, true, false, "img/items/clothing-3.png",
                    "为了人的温暖与安全而特制的衬衫。", 1, 8),
                new ItemVO("clothing_upper_5", "Scavenger's raincoat", "Shirt", {"fight defence": 0, warmth: 25, "radiation protection": 40, "poison protection": 60}, true, true, false, "img/items/clothing-3.png",
                    "有着探索者所期望着的最好的防护性。", 1, 9),
            ],
            clothing_lower: [
                new ItemVO("clothing_lower_1", "Ragged pants", "Legs", {warmth: 1}, true, false, false, "img/items/clothing-rags.png",
                    "基本不能算作是衣服，但现在也只能穿它了。", 1, 2),
                new ItemVO("clothing_lower_2", "Factory uniform pants", "Legs", {"fight defence": 1, warmth: 3}, true, false, false, "img/items/clothing-2.png",
                    "曾是城市地下的标准制服。", 5, 4),
                new ItemVO("clothing_lower_3", "Guard uniform pants", "Legs", {"fight defence": 2, warmth: 3}, true, true, false, "img/items/clothing-2.png",
                    "看起来很正式，但没有很好的保护能力。", 12, 4),
                new ItemVO("clothing_lower_4", "Padded pants", "Legs", {"fight defence": 15, warmth: 5}, true, true, false, "img/items/clothing-3.png",
                    "保护自身，免受咬伤和划伤。", 13, -1),
                new ItemVO("clothing_lower_5", "Long underwear", "Legs", {"fight defence": 1, warmth: 20}, true, true, false, "img/items/clothing-3.png",
                    "没有什么能比一条秋裤更能给你温暖了。", 15, 6),
            ],
            clothing_head: [
                new ItemVO("clothing_head_0", "Sunglasses", "Head", {"sunblindness protection": 30}, true, false, false, "img/items/clothing-hat-1.png",
                    "如果有阳光的话，有它就很便利了。", 2, 8),
                new ItemVO("clothing_head_1", "Wollen hat", "Head", {"fight defence": 1, warmth: 10}, true, true, false, "img/items/clothing-hat-1.png",
                    "有基础温暖能力的帽子。", 1, 5),
                new ItemVO("clothing_head_2", "Pollution mask", "Head", {"poison protection": 15}, true, false, false, "img/items/clothing-hat-1.png",
                    "在受污染的空气中对人有微弱的保护作用。", 4, 7),
                new ItemVO("clothing_head_3", "Scrap metal helmet", "Head", {"fight defence": 5, warmth: 5, "radiation protection": 5, "poison protection": 5, "sunblindness protection": 10}, true, true, false, "img/items/clothing-hat-2.png",
                    "末日后骑士的完美装备。", 5, -1),
                new ItemVO("clothing_head_4", "Gas mask", "Head", {"fight defence": 5, warmth: 5, "radiation protection": 15, "poison protection": 30, "sunblindness protection": 10}, true, false, false, "img/items/clothing-hat-2.png",
                    "在危险的环境中给你一定的安全感。", 11, 8),
                new ItemVO("clothing_head_5", "Explorer's helmet", "Head", {"fight defence": 30, warmth: 10, "radiation protection": 20, "poison protection": 10, "sunblindness protection": 50}, true, true, false, "img/items/clothing-hat-3.png",
                    "设计来专门在城市中探索的头盔。", 15, -1),
            ],
            clothing_hands: [
                new ItemVO("clothing_hands_1", "Mittens", "Hands", {"warmth": 10}, true, true, false, "img/items/clothing-hand-0.png",
                    "没有什么比毛茸茸的连指手套更保暖的了。", 2, 5),
                new ItemVO("clothing_hands_2", "Work gloves", "Hands", {"warmth": 5, "radiation protection": 2, "poison protection": 2}, true, true, false, "img/items/clothing-hand-0.png",
                    "对手部有基本的保护作用。", 5, 5),
                new ItemVO("clothing_hands_3", "Quality gloves", "Hands", {"warmth": 5, "radiation protection": 5, "poison protection": 10}, true, true, false, "img/items/clothing-hand-0.png",
                    "没有一个搜索者因为拥有好手套而后悔。", 8, 6),
                new ItemVO("clothing_hands_4", "Scavenger's gloves", "Hands", {"fight defence": 5, warmth: 15, "radiation protection": 10, "poison protection": 10}, true, true, false, "img/items/clothing-hand-0.png",
                    "几乎可以从所有的环境危害中保护自身的手套。", 15, 9),
            ],
            shoes: [
                new ItemVO("shoe_1", "Improvised flip-flops", "Shoes", {"movement": 0.9}, true, true, false, "img/items/shoe-1.png",
                    "保护搜索人的脚免受周围地面尖锐物的伤害。", 1, 6),
                new ItemVO("shoe_2", "Worn trainers", "Shoes", {"movement": 0.8}, true, false, false, "img/items/shoe-2.png",
                    "走在大多数地方都显得合理、得体的鞋子", 7, 4),
                new ItemVO("shoe_3", "Hiking boots", "Shoes", {"movement": 0.5}, true, false, false, "img/items/shoe-3.png",
                    "像这样的优质鞋子能让旅行变得更简单。", 14, 7),
            ],
            follower: [
            ],
            bag: [
                new ItemVO("bag_0", "Plastic bag", "Bag", {"bag": WorldCreatorConstants.BAG_BONUS_1}, true, true, false, "img/items/bag-0.png",
                    "它并不是很好看，但比起用手拿和口袋装，它可以让人随身携带更多的东西。", 1, 1),
                new ItemVO("bag_1", "Basic backpack", "Bag", {"bag": WorldCreatorConstants.BAG_BONUS_2}, true, true, false, "img/items/bag-1.png",
                    "一个更宽的袋子，有更多口袋。", WorldCreatorConstants.LEVEL_ORDINAL_BAG_2, 4),
                new ItemVO("bag_2", "Jumbo backpack", "Bag", {"bag": WorldCreatorConstants.BAG_BONUS_3}, true, true, false, "img/items/bag-1.png",
                    "一个有大量空间的巨大背包。", 5, WorldCreatorConstants.LEVEL_ORDINAL_BAG_3, 6),
                new ItemVO("bag_3", "Hicker's rucksack", "Bag", {"bag": WorldCreatorConstants.BAG_BONUS_4}, true, false, false, "img/items/bag-1.png",
                    "有了这个背包，很可能在背包装满前就背不动了。", WorldCreatorConstants.LEVEL_ORDINAL_BAG_4, 6),
                new ItemVO("bag_4", "Scavenger bag", "Bag", {"bag": WorldCreatorConstants.BAG_BONUS_5}, true, false, false, "img/items/bag-1.png",
                    "一个很实用的背包，里面有很多口袋。", WorldCreatorConstants.LEVEL_ORDINAL_BAG_5, 8),
                new ItemVO("bag_5", "Automatic luggage", "Bag", {"bag": WorldCreatorConstants.BAG_BONUS_6}, true, true, false, "img/items/bag-3.png",
                    "一个会自动跟随主人的机械箱。再也不用自己拿着所有东西了。", WorldCreatorConstants.LEVEL_ORDINAL_BAG_6, 10),
            ],
            artefact: [
                new ItemVO("artefact_ground_1", "Runestone", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "一块令人费解的石头，上面有一个古老的符文。", 3, 8),
                new ItemVO("artefact_ground_2", "Charred seed", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "据说种子内是包含生命的，它们在黑暗的城市中不会生长。", 10, 10),
                new ItemVO("artefact_ground_3", "Round stone", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "光滑的石头，握在手中正合适。给人一种平静的感觉。", 3, 6),
                new ItemVO("artefact_ground_4", "Leather pouch", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "带绳子的小皮袋，可以戴到脖子上。它里面装着一些粉末。", 1, 6),
                new ItemVO("artefact_surface_1", "Canned tuna", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "过去的剩饭，据说它以前的时候里面装着鱼，在它还在地表的时候。", 15, 5),
                new ItemVO("artefact_surface_2", "ID Chip", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "像这样的芯片曾经被植入在人们的皮肤下，赋予他们一定的力量。它可能已经不能用了。", 15, 7),
                new ItemVO("artefact_surface_3", "Scientist's notebook", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "这本笔记已经破损了，但大部分还是可以识别的。它似乎包含了一些计算，这些计算与某种大型复杂的汽车在很长的距离内的耗油量有关。", 15, 7),
                new ItemVO("artefact_history_1", "Fountain pen", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "作为一种书写工具，它在很早以前就被淘汰了。但是在智者和哲人当中，它作为知识的象征仍然在流行。", 1, 6),
                new ItemVO("artefact_history_2", "Pearl", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "一个美丽的球体，据说是在大海中成形的。大海是由大量的水所组成的，是所有生命的起源。", 7, 8),
                new ItemVO("artefact_history_3", "CD", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "一个老旧的圆形数据储存器，上面写着“备份”。如果没有一台电子计算机，即使它是可读的，也无法获取信息。", 1, 6),
                new ItemVO("artefact_doom_1", "Volcanic rock", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "一块令人不安的黑色岩石。在上面刻着一些东西，使用的是某种不熟悉的语言。", 4, 7),
                new ItemVO("artefact_doom_2", "Temple key", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "沉重的钥匙，上面有着恶魔般的鳗鱼样装饰，是一种非常复杂的雕刻，栩栩如生。触碰它的时候有一种奇异的冰冷感。", 1, 7),
                new ItemVO("artefact_doom_3", "Seashell", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "脆弱的、黄色的、浅粉色的贝壳，一定是从博物馆里抢来的。", 1, 9),
                new ItemVO("artefact_doom_4", "Pamphlet", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "较厚的小册子上印着醒目的政治传单，力劝“下水道”中的居民反对隔离。", 1, 5),
                new ItemVO("artefact_doom_5", "Starchart", "Artefact", null, false, false, false, "img/items/artefact-test.png",
                    "复杂的星图，上面的计算表明了发生在783年的事件。", 15, 8),
            ],
            ingredient: [
                new ItemVO("res_matches", "Matches", "Ingredient", null, false, false, false, "img/items/res-matches.png", "用来制造东西。"),
                new ItemVO("res_bands", "Rubber bands", "Ingredient", null, false, false, false, "img/items/res-bands.png", "用来制造东西。"),
                new ItemVO("res_silk", "Spider silk", "Ingredient", null, false, false, false, "img/items/res-silk.png", "用来制造东西。"),
            ],
            exploration: [
                new ItemVO("exploration_1", "Lock pick", "Exploration", null, false, true, false, "img/items/exploration-1.png", "探索和侦察时有用的工具。"),
                new ItemVO("first_aid_kit_1", "Basic First Aid Kit", "Exploration", null, false, true, true, "img/items/firstaid-1.png", "在旅途中治疗轻伤。", 3, 6),
                new ItemVO("first_aid_kit_2", "Full First Aid Kit", "Exploration", null, false, true, true, "img/items/firstaid-2.png", "旅途中治疗所有伤口。", 10, 8),
                new ItemVO("glowstick_1", "Glowstick", "Exploration", null, false, true, true, "img/items/glowstick-1.png", "临时的光源。可以用来分散注意力。", 1, 8)
            ],
            uniqueEquipment: [
                new ItemVO("equipment_map", "Map", "UniqueEquipment", null, false, false, false, "img/items/exploration-map.png", "帮助你在城市中寻找方向。"),
            ],
        },
        
        getItemByID: function (id) {
            if (id.indexOf("follower-") >= 0)
                return this.getFollowerByID(id);
            for (var type in this.itemDefinitions ) {
                for (var i in this.itemDefinitions[type]) {
                    var item = this.itemDefinitions[type][i];
                    if (item.id === id) {
                        return item;
                    }
                }
            }
            return null;
        },

        getItemDefaultBonus: function (item) {
            switch (item.type) {
                case ItemConstants.itemTypes.light:
                    return ItemConstants.itemBonusTypes.light;
                case ItemConstants.itemTypes.weapon:
                    return ItemConstants.itemBonusTypes.fight_att;
                case ItemConstants.itemTypes.shoes:
                    return ItemConstants.itemBonusTypes.movement;
                case ItemConstants.itemTypes.bag:
                    return ItemConstants.itemBonusTypes.bag;
                case ItemConstants.itemTypes.clothing_over:
                case ItemConstants.itemTypes.clothing_upper:
                case ItemConstants.itemTypes.clothing_lower:
                case ItemConstants.itemTypes.clothing_head:
                case ItemConstants.itemTypes.clothing_hands:
                case ItemConstants.itemTypes.follower:
                    return ItemConstants.itemBonusTypes.fight_def;
                default:
                    return null;
            }
        },
        
        getRequiredCampOrdinalToCraft: function (item) {
            var campOrdinal = 0;
            var reqs = PlayerActionConstants.requirements["craft_" + item.id];
            if (reqs && reqs.upgrades) {
                var requiredTech = Object.keys(reqs.upgrades);
                for (var k = 0; k < requiredTech.length; k++) {
                    var requiredTechCampOrdinal = UpgradeConstants.getMinimumCampOrdinalForUpgrade(requiredTech[k]);
                    campOrdinal = Math.max(campOrdinal, requiredTechCampOrdinal);
                }
            }
            return campOrdinal;
        },
        
        getFollower: function (level, campCount) {
            var minStrength = campCount;
            var maxStrength = 1.5 + campCount * 1.5;
            var strengthDiff = maxStrength - minStrength;
            var strength = Math.round(minStrength + strengthDiff * Math.random());
            var type = "d";
            if (level < 5)
                type = "g";
            if (level > 15)
                type = "c";
            var id = "follower-" + strength + "-" + type;
            return this.getFollowerByID(id);
        },
        
        getFollowerByID: function (id) {
            var name = "随从";
            var type = this.itemTypes.follower;
            var strength = parseInt(id.split("-")[1]);

            // TODO persist image depending on id
            var icon = "img/items/follower-" + Math.floor(Math.random() * 4 + 1) + ".png";

            // TODO more varied follower descriptions
            var description = "同意和你一起探险的伙伴。";

            return new ItemVO(id, name, type, {"fight attack": strength}, true, false, false, icon, description);
        },
        
        getBag: function (levelOrdinal) {
            if (levelOrdinal < WorldCreatorConstants.LEVEL_ORDINAL_BAG_2) {
                return this.itemDefinitions.bag[0];
            }
            if (levelOrdinal < WorldCreatorConstants.LEVEL_ORDINAL_BAG_3) {
                return this.itemDefinitions.bag[1];
            }
            if (levelOrdinal < WorldCreatorConstants.LEVEL_ORDINAL_BAG_4) {
                return this.itemDefinitions.bag[2];
            }
            if (levelOrdinal < WorldCreatorConstants.LEVEL_ORDINAL_BAG_5) {
                return this.itemDefinitions.bag[3];
            }
            if (levelOrdinal < WorldCreatorConstants.LEVEL_ORDINAL_BAG_6) {
                return this.itemDefinitions.bag[4];
            }
            return this.itemDefinitions.bag[5];
        },
        
        getShoes: function (campOrdinal) {
            if (campOrdinal < this.itemDefinitions.shoes[1].requiredCampOrdinal) {
                return this.itemDefinitions.shoes[0];
            }
            if (campOrdinal < this.itemDefinitions.shoes[2].requiredCampOrdinal) {
                return this.itemDefinitions.shoes[Math.floor(2 * Math.random())];
            }
            return this.itemDefinitions.shoes[Math.floor(3 * Math.random())];
        },
        
        getDefaultWeapon: function (campOrdinal) {
            var totalWeapons = this.itemDefinitions.weapon.length;
            var weapon = Math.max(1, Math.floor(campOrdinal / WorldCreatorConstants.CAMPS_TOTAL * totalWeapons));
            return this.itemDefinitions.weapon[weapon - 1];
        },
        
        getIngredient: function () {
            var i = (this.itemDefinitions.ingredient.length) * Math.random();
            return this.itemDefinitions.ingredient[parseInt(i)];
        }
    };

    return ItemConstants;

});
